package com.jf.springcloud.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.core.RandomLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-02-14
 * Time:21:46
 */
@Configuration
/*
 * 1. 配置的服务名必须和注册中心上的服务名一致(一般都为大写)
 * 2. 自定义的LoadBalanceConfig类不能加@Configuration注解
 */
@LoadBalancerClient(value = "MEMBER-SERVICE-PROVIDER", configuration = LoadBalanceConfig.class)
public class CustomizationConfig {
    /*
    * @Description: RestTemplate配置负载均衡, 采用的负载均衡算法是默认是轮询算法, 已重定义为随机算法, 底层是ribbon
     */
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
